<template>
	<view>
		<image src="/static/work1.jpg" mode="" class="img_bg" style="top: 0;"></image> 
		<view class="margin-r30 margin-l30">
			<block v-for="(item,index) in list" :key="index">
				<view class="card margin-t30 relative z-index" style="" @tap="toDetail1(item.id,item.add_time,item.status)">
					<view :class="item.status=='1'?'jiaobiao':'jiaobiao2'">
						{{item.status==1?'正常':'异常'}}
					</view>
					
					<!-- <view class="text-36">{{item.danger_name?item.danger_name:"-"}}</view> -->  <!-- 设备 -->
					<view class="display justify-between margin-t22">
		
						<view class="font-gray1">巡检时间</view>
						<view :class="item.danger_level==1?'font-0':item.danger_level==2?'font-1':item.danger_level==3?'font-2':item.danger_level==4?'font-3':''">{{item.add_time?item.add_time:"-"}}</view>
					</view>
					<view class="display justify-between margin-t22">
						<view class="font-gray1 ">巡检人</view>
						<view :class="item.danger_level==1?'font-0':item.danger_level==2?'font-1':item.danger_level==3?'font-2':item.danger_level==4?'font-3':''">{{item.userinfo.nickname?item.userinfo.nickname:"-"}}</view>
					</view>
					<view class="display justify-between margin-t22">
						<view class="font-gray1 ">所属部门</view>
						<view :class="item.danger_level==1?'font-0':item.danger_level==2?'font-1':item.danger_level==3?'font-2':item.danger_level==4?'font-3':''">{{item.userinfo.position_name?item.userinfo.position_name:"公司"}}</view>
					</view>
					<!-- 重新指派 -->
					<!-- <view class="" style="width: 200rpx;margin-left: 35%;color: #D9000F;border: 1rpx solid #D9000F;" @click.stop="reset(item)">
						点此重新指派
					</view> -->
				</view>
			</block>
			
			<view class="loading" v-show="!isShow">
				{{loadingText}}
			</view>
			<view class="text-center noNotice" v-show="isShow" style="margin-top: 200upx;">
				<image src="/static/notice.png" class="noticeImg"></image>
				<view class="font-gray margin-t30">暂无巡检记录~</view>
			</view>
		</view>
	</view>
</template>

<script>
	var page = 1,
		timer;
	export default {
		data() {
			return {
				uid:'',
				token:'',
				list:[],
				
				loadingText: '上拉加载更多',
				isShow: false
			}
		},
		onLoad() {
			this.uid = uni.getStorageSync('user').uid;
			this.token = uni.getStorageSync('user').token;
			this.getInspectionList()
		},
		onPullDownRefresh: function() {
			this.getInspectionList()
		},
		onReachBottom: function() {
			let that = this
			if (timer != null) {
				clearTimeout(timer)
			}
			timer = setTimeout(function() {
				that.getNewInspectionList();
			}, 500);
		},
		methods: {
			//重新指派
			reset(item){
				console.log(item.is_reassign)
				if(item.is_reassign === 1){
					uni.request({
						url: 'https://aqmore.sxpz.vip/AppApi/Convenient/setReAssign?uid=' + this.uid + '&token=' + this.token +
							'&id=' + item.id,
						method: 'GET',
						header: {
							'content-type': 'application/x-www-form-urlencoded'
						},
						success: function(res) {
							item.inspection_status=0
							console.log(res.data.datas.msg)
							uni.showToast({
								title:res.data.datas.msg
							})
						},
						fail() {
							uni.showToast({
								title:res.data.datas.msg
							})
						}
					})
				}else{
					uni.showToast({
						title:'您无法重新指派',
						icon:'none'
					})
				}
			},
			getInspectionList(){
				var _that=this
				page = 1
				
				uni.showNavigationBarLoading();
				this.loadingText = '上拉加载更多'
				uni.request({
					url:'https://aqmore.sxpz.vip/AppApi/Convenient/getInspectionList?uid='+this.uid + '&token=' + this.token+'&p=' + page,
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success:function(res){
						if (res.data.code == 200) {
							if (res.data.datas.length == 0) {
								_that.isShow = true
							}
							_that.list = res.data.datas
							//console.log(_that.list)
						}
						if (res.data.code == 100) {
							//console.log(res)
							uni.showToast({
								title: res.data.datas.msg,
								icon: 'none'
							})
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/index/index'
								})
								try {
									uni.removeStorageSync('user');
									//console.log('chenggonmg')
								} catch (e) {
									// error
								}
							}, 1500)
						}
						uni.stopPullDownRefresh();
						uni.hideNavigationBarLoading();
						page++;
					}
				})
			},
			getNewInspectionList() {
				var that = this
				if (this.loadingText == '没有更多待整改任务') {
					return false
				}
				this.loadingText = '加载中...'
				uni.request({
					url: 'https://aqmore.sxpz.vip/AppApi/Convenient/getInspectionList?uid=' + this.uid + '&token=' + this.token +
						'&p=' + page,
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: function(res) {
						uni.hideNavigationBarLoading();
						if (res.data.datas.length == 0) {
							that.loadingText = '没有更多待整改任务';
							return false
						}
						if (res.data.code == 200) {
							var newlist = res.data.datas
							that.list = that.list.concat(newlist)
							//console.log(that.list)
						}
						page++;
					}
				})
			},
			
			toDetail1(e, f, g) { //f为时间  g为状态 正常或异常
			console.log(12312)
				uni.navigateTo({
					url: 'takePictureDetail?id='+e+'&time='+f
					 // 'takePictuerDetail?id=' + e + '&time=' + f + '&zhuangtai=' + g
				})
			}
		}
	}
</script>

<style>
	.jiaobiao{
			position: absolute;
			height: 50upx;
			width: 100upx;
			right: 0;
			font-size: 100%;
			background-color: #00aa00;
			color: #FFFFFF;
			top:-3upx;
			border-radius: 10%;
			text-align: center;
		}
		.jiaobiao2{
			position: absolute;
			height: 50upx;
			width: 100upx;
			right: 0;
			font-size: 100%;
			background-color: #ff0000;
			color: #FFFFFF;
			top:-3upx;
			border-radius: 10%;
			text-align: center;
		}
		.loading {
			line-height: 2em;
			text-align: center;
			color: #808080;
			margin-top: 30upx;
			margin-bottom: 30rpx;
		}

</style>
